package com.garmin.tw.garminpcsync.android.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.garmin.tw.garminpcsync.android.AsyncImageView;
import com.garmin.tw.garminpcsync.android.R;
import com.garmin.tw.garminpcsync.common.domain.xmlrpc.TravelRoute;

public class TravelRouteAdapter extends BaseAdapter {
	
	private Activity activity;
	
	private List<TravelRoute> travelRouteList;
	
	private static LayoutInflater inflater = null;
	
	//public GarageAdapter(Activity a, List<String> _descriptionList, List<String> _fileSizeList, List<String> _thumbnailUrlList, List<String> _downloadUrlList) {
	public TravelRouteAdapter(Activity a, List<TravelRoute> _travelRouteList) {
		activity = a;
		
		this.travelRouteList = _travelRouteList;
		
		inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		return this.travelRouteList.size();
	}
	
	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi=convertView;
		if(convertView == null) {
			vi = inflater.inflate(R.layout.travelroute_item, null);
		}
		
		AsyncImageView thumbnail = (AsyncImageView)vi.findViewById(R.id.list_image);
		TextView description = (TextView)vi.findViewById(R.id.description);
		TextView downloadUrl = (TextView)vi.findViewById(R.id.downloadUrl);
		TextView fileSize = (TextView)vi.findViewById(R.id.fileSize);

		// Setting all values in listview
		thumbnail.loadImage(this.travelRouteList.get(position).getThumbnailURL());
		description.setText(this.travelRouteList.get(position).getTitle());
		downloadUrl.setText(this.travelRouteList.get(position).getDownloadURL());
		fileSize.setText(this.travelRouteList.get(position).getFileSize().toString());
		
		return vi;
	}
}
